package han.chensing.latos;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;

import java.io.ByteArrayInputStream;
import java.io.Serializable;

import han.chensing.latos.game.util.SerUtil;

public class Setting implements Serializable {
    private static final long serialVersionUID = -591402320330594081L;
    public static final String path = "cirno-latos.set";
    public boolean multiThreadInput=false;
    public boolean useAbsoluteTime=true;

    public static Setting fromFile(){
        FileHandle local = Gdx.files.local(path);
        try {
            if (!local.exists())
                return new Setting();
            return SerUtil.toObject(local.read(), Setting.class);
        } catch (Exception e) {
            e.printStackTrace();
            return new Setting();
        }
    }

    public void toFile(){
        try {
            byte[] bytes = SerUtil.toBytes(this);
            FileHandle local = Gdx.files.local(path);
            ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(bytes);
            local.write(byteArrayInputStream,false);
            byteArrayInputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
